# when in arch linux

import os, re, sys, subprocess

def str1(a):
    v= re.search(r'\'.+\'', a)
    return v.group().strip("'")

with open("/var/log/pacman.log", encoding='utf8', mode='r') as f:
    v= f.readlines()

#print(v)
r1= re.compile(".+ \[PACMAN\] Running .+pacman \-S ")
v1= list(filter(r1.match, v))
v3= [v.index(i) for i in v1]
v2= list(map(str1, v1))
v5= [str(i) for i in range(len(v2))]
v6= [']\t'.join(i) for i in zip(v5, v2)]
print(' ['+'\n ['.join(v6))
v4= input(" :")

v7= v[v3[int(v4)] : v3[int(v4)+1]]
print(v7)
v9= re.findall(r'.+ installed (\S+) .+' ,''.join(v7))[::-1]
print(v9)

pause= input("Ready to uninstall %s, Sure?" %' '.join(v9))
if pause!='':
    sys.exit(0)

for i in v9:
    os.system("sudo pacman -R --noconfirm %s" %i)
